library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.3     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(tidymodels)
## Registered S3 method overwritten by 'tune':
##   method                   from   
##   required_pkgs.model_spec parsnip
## ── Attaching packages ────────────────────────────────────── tidymodels 0.1.3 ──
## ✓ broom        0.7.8      ✓ rsample      0.1.0 
## ✓ dials        0.0.9      ✓ tune         0.1.6 
## ✓ infer        0.5.4      ✓ workflows    0.2.3 
## ✓ modeldata    0.1.1      ✓ workflowsets 0.1.0 
## ✓ parsnip      0.1.7      ✓ yardstick    0.0.8 
## ✓ recipes      0.1.16
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## x scales::discard() masks purrr::discard()
## x dplyr::filter()   masks stats::filter()
## x recipes::fixed()  masks stringr::fixed()
## x dplyr::lag()      masks stats::lag()
## x yardstick::spec() masks readr::spec()
## x recipes::step()   masks stats::step()
## • Use tidymodels_prefer() to resolve common conflicts.
library(janitor)
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
library(skimr)
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(GGally)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
library(kableExtra) # -- make nice looking resutls when we knitt 
library(vip)        # --  tidymodels variable importance
## 
## Attaching package: 'vip'
## The following object is masked from 'package:utils':
## 
##     vi
library(fastshap)   # -- shapley values for variable importance 
## 
## Attaching package: 'fastshap'
## The following object is masked from 'package:vip':
## 
##     gen_friedman
## The following object is masked from 'package:dplyr':
## 
##     explain
library(rpart.plot) # -- plotting decision trees 
## Loading required package: rpart
## 
## Attaching package: 'rpart'
## The following object is masked from 'package:dials':
## 
##     prune
library(MASS)
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
library(caret)
## Loading required package: lattice
## 
## Attaching package: 'caret'
## The following objects are masked from 'package:yardstick':
## 
##     precision, recall, sensitivity, specificity
## The following object is masked from 'package:purrr':
## 
##     lift
library(rpart)

import data

org<- read_csv("organics.csv") %>% clean_names()
## Rows: 22223 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): DemClusterGroup, DemGender, DemReg, DemTVReg, PromClass
## dbl (8): ID, DemAffl, DemAge, DemCluster, PromSpend, PromTime, TargetBuy, Ta...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(org)
neworg <- read_csv("new_organics.csv") %>% clean_names()
## Rows: 150 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): DemClusterGroup, DemGender, DemReg, DemTVReg, PromClass
## dbl (6): ID, DemAffl, DemAge, DemCluster, PromSpend, PromTime
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(neworg)

remove columns

subset(org,select=c(dem_affl,dem_age,dem_cluster_group,
                    dem_gender,dem_reg,dem_tv_reg,
                    prom_class,prom_spend,prom_time,target_buy))->org
org
colnames(org)<-make.unique(names(org))

skim organics

org %>%skim()
Data summary
Name Piped data
Number of rows 22223
Number of columns 10
_______________________
Column type frequency:
character 5
numeric 5
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
dem_cluster_group 674 0.97 1 1 0 7 0
dem_gender 2512 0.89 1 1 0 3 0
dem_reg 465 0.98 5 10 0 5 0
dem_tv_reg 465 0.98 4 12 0 13 0
prom_class 0 1.00 3 8 0 4 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
dem_affl 1085 0.95 8.71 3.42 0.00 6.00 8 11 34.0 ▃▇▁▁▁
dem_age 1508 0.93 53.80 13.21 18.00 44.00 54 64 79.0 ▁▅▇▇▆
prom_spend 0 1.00 4420.59 7559.05 0.01 0.01 2000 6000 296313.8 ▇▁▁▁▁
prom_time 281 0.99 6.56 4.66 0.00 4.00 5 8 39.0 ▇▅▁▁▁
target_buy 0 1.00 0.25 0.43 0.00 0.00 0 0 1.0 ▇▁▁▁▂
neworg%>%skim()
Data summary
Name Piped data
Number of rows 150
Number of columns 11
_______________________
Column type frequency:
character 5
numeric 6
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
dem_cluster_group 0 1 1 1 0 6 0
dem_gender 0 1 1 1 0 3 0
dem_reg 0 1 5 10 0 5 0
dem_tv_reg 0 1 4 12 0 12 0
prom_class 0 1 3 8 0 4 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
id 0 1 75.57 43.56 1.00 38.25 75.50 112.75 158 ▇▇▇▇▆
dem_affl 0 1 8.37 3.40 2.00 6.00 8.00 10.00 26 ▃▇▁▁▁
dem_age 0 1 54.09 13.21 22.00 45.00 54.00 64.75 79 ▂▅▇▆▅
dem_cluster 0 1 27.57 16.07 1.00 13.00 27.00 40.75 53 ▅▇▇▅▇
prom_spend 0 1 3516.06 5025.91 0.01 0.01 1578.45 5875.00 32050 ▇▁▁▁▁
prom_time 0 1 6.94 4.94 1.00 4.00 6.00 8.00 30 ▇▆▁▁▁

Explore variables

Explore target

org %>%
  ggplot(aes(x=target_buy)) +
  geom_histogram(stat="count") +
  labs(title = "Buy vs. Not Buy ")
## Warning: Ignoring unknown parameters: binwidth, bins, pad

org %>%
  group_by(target_buy) %>%
  summarize(n=n()) %>%
  ungroup() %>%
  mutate(pct = n/sum(n))

Explore numerics

org<-org%>%
  mutate(target_buy=as.factor(target_buy))
# -- comparative histogram
ggplot(org,aes(x=dem_affl))+
  geom_histogram(data=subset(org,target_buy==0),fill="red", alpha = 0.5, bins = 50) +
  geom_histogram(data=subset(org,target_buy==1),fill = "blue", alpha = 0.5,  bins = 50) +
  labs(title="Affluence Grade by target_buy = 0 (red) vs by target_buy = 1 (blue)")
## Warning: Removed 793 rows containing non-finite values (stat_bin).
## Warning: Removed 292 rows containing non-finite values (stat_bin).

ggplot(org,aes(x=dem_age))+
  geom_histogram(data=subset(org,target_buy==0),fill="red", alpha = 0.5, bins = 50) +
  geom_histogram(data=subset(org,target_buy==1),fill = "blue", alpha = 0.5,  bins = 50) +
  labs(title="Age by target_buy = 0 (red) vs by target_buy = 1 (blue)")
## Warning: Removed 1103 rows containing non-finite values (stat_bin).
## Warning: Removed 405 rows containing non-finite values (stat_bin).

ggplot(org,aes(x=prom_spend))+
  geom_histogram(data=subset(org,target_buy==0),fill="red", alpha = 0.5, bins = 50) +
  geom_histogram(data=subset(org,target_buy==1),fill = "blue", alpha = 0.5,  bins = 50) +
  labs(title="Total amount spent in the store this year by target_buy = 0 (red) vs by target_buy = 1 (blue)")

ggplot(org,aes(x=prom_time))+
  geom_histogram(data=subset(org,target_buy==0),fill="red", alpha = 0.5, bins = 50) +
  geom_histogram(data=subset(org,target_buy==1),fill = "blue", alpha = 0.5,  bins = 50) +
  labs(title="Time as loyalty card member by target_buy = 0 (red) vs by target_buy = 1 (blue)")
## Warning: Removed 194 rows containing non-finite values (stat_bin).
## Warning: Removed 87 rows containing non-finite values (stat_bin).

# -- comparative boxplots
ggplot(org, aes(x=dem_affl, y=target_buy)) + geom_boxplot() +labs(title = "Affluence Grade")
## Warning: Removed 1085 rows containing non-finite values (stat_boxplot).

ggplot(org, aes(x=dem_age, y=target_buy)) + geom_boxplot() +labs(title = "Age")
## Warning: Removed 1508 rows containing non-finite values (stat_boxplot).

ggplot(org, aes(x=prom_spend, y=target_buy)) + geom_boxplot() +labs(title = "Total amount spent in the store this year")

ggplot(org, aes(x=prom_time, y=target_buy)) + geom_boxplot() +labs(title = "Time as loyalty card member")
## Warning: Removed 281 rows containing non-finite values (stat_boxplot).

Explore characters

char_explore <- function(col){
  org %>%
    ggplot(., aes(!!as.name(col))) + 
    geom_bar(aes(fill = target_buy), position = "fill") 
}

# -- for each character column if it doesnt equal customer id then create a chart
for (column in names(org %>% select_if (is_character))){
  chrt <- char_explore(column)
    print(chrt)
  
}

# Generate Models ## 0. Make Factors!

org %>%
    mutate_if(is.character, factor)-> org_prep
org_prep$target_buy <- as.factor(org_prep$target_buy)
head(org_prep)

1. Partition your data 70/30 (train / test split)

# -- set a random seed for repeatablity 
set.seed(43)

# -- performs our train / test split 
org_split <- initial_split(org_prep, prop = 0.7)

# -- extract the training data 
org_train <- training(org_split)
# -- extract the test data 
org_test <- testing(org_split)

sprintf("Train PCT : %1.2f%%", nrow(org_train)/ nrow(org_prep) * 100)
## [1] "Train PCT : 70.00%"
sprintf("Test  PCT : %1.2f%%", nrow(org_test)/ nrow(org_prep) * 100)
## [1] "Test  PCT : 30.00%"

2. Recipe

org_recipe <- recipe(target_buy ~ ., data = org_train) %>%
  step_mutate(dem_gender=replace_na(dem_gender,"U")) %>%
  step_modeimpute(all_nominal(), -all_outcomes()) %>%
  step_medianimpute(all_numeric()) %>%
  step_dummy(all_nominal(), -all_outcomes()) %>%
  prep()
## Warning: `step_medianimpute()` was deprecated in recipes 0.1.16.
## Please use `step_impute_median()` instead.
## Warning: `step_modeimpute()` was deprecated in recipes 0.1.16.
## Please use `step_impute_mode()` instead.
org_recipe
## Data Recipe
## 
## Inputs:
## 
##       role #variables
##    outcome          1
##  predictor          9
## 
## Training data contained 15556 data points and 4005 incomplete rows. 
## 
## Operations:
## 
## Variable mutation for dem_gender [trained]
## Mode Imputation for dem_cluster_group, dem_gender, ... [trained]
## Median Imputation for dem_affl, dem_age, prom_spend, prom_time [trained]
## Dummy variables from dem_cluster_group, dem_gender, dem_reg, ... [trained]

3. Bake

bake_train <- bake(org_recipe, new_data = org_train)
bake_test  <- bake(org_recipe, new_data = org_test)

4.Fit

4.1 Default Decision tree

org_tree <- decision_tree(mode="classification") %>%
                  set_engine("rpart") %>%
                  fit(target_buy ~ ., data = bake_train)

org_tree
## parsnip model object
## 
## Fit time:  1.9s 
## n= 15556 
## 
## node), split, n, loss, yval, (yprob)
##       * denotes terminal node
## 
##  1) root 15556 3830 0 (0.7537927 0.2462073)  
##    2) dem_age>=44.5 11714 1844 0 (0.8425815 0.1574185)  
##      4) dem_affl< 12.5 10630 1359 0 (0.8721543 0.1278457) *
##      5) dem_affl>=12.5 1084  485 0 (0.5525830 0.4474170)  
##       10) dem_affl< 16.5 932  368 0 (0.6051502 0.3948498) *
##       11) dem_affl>=16.5 152   35 1 (0.2302632 0.7697368) *
##    3) dem_age< 44.5 3842 1856 1 (0.4830817 0.5169183)  
##      6) dem_affl< 9.5 2227  854 0 (0.6165245 0.3834755)  
##       12) dem_gender_U>=0.5 361   50 0 (0.8614958 0.1385042) *
##       13) dem_gender_U< 0.5 1866  804 0 (0.5691318 0.4308682)  
##         26) dem_gender_M>=0.5 540  145 0 (0.7314815 0.2685185) *
##         27) dem_gender_M< 0.5 1326  659 0 (0.5030166 0.4969834)  
##           54) dem_affl< 7.5 685  281 0 (0.5897810 0.4102190) *
##           55) dem_affl>=7.5 641  263 1 (0.4102964 0.5897036) *
##      7) dem_affl>=9.5 1615  483 1 (0.2990712 0.7009288) *
rpart.plot(org_tree$fit, roundint=FALSE, extra=3)

Decision tree 2

set.seed(123)
org_tree1 <- train(target_buy ~ .,
                   data = bake_train, 
                  method="rpart",
                  trControl = trainControl("cv", number = 40),
                  tuneLength = 20)
plot(org_tree1)

org_tree1$bestTune
org_tree2 <- decision_tree(mode="classification",
                            cost_complexity = 0.0011,
                            tree_depth = 6,
                            min_n = 2) %>%
                  set_engine("rpart") %>%
                  fit(target_buy ~ ., data=bake_train)

org_tree2$fit
## n= 15556 
## 
## node), split, n, loss, yval, (yprob)
##       * denotes terminal node
## 
##   1) root 15556 3830 0 (0.75379275 0.24620725)  
##     2) dem_age>=44.5 11714 1844 0 (0.84258153 0.15741847)  
##       4) dem_affl< 12.5 10630 1359 0 (0.87215428 0.12784572) *
##       5) dem_affl>=12.5 1084  485 0 (0.55258303 0.44741697)  
##        10) dem_affl< 16.5 932  368 0 (0.60515021 0.39484979)  
##          20) dem_gender_U>=0.5 152   27 0 (0.82236842 0.17763158) *
##          21) dem_gender_U< 0.5 780  341 0 (0.56282051 0.43717949)  
##            42) dem_gender_M>=0.5 207   55 0 (0.73429952 0.26570048) *
##            43) dem_gender_M< 0.5 573  286 0 (0.50087260 0.49912740)  
##              86) dem_age>=65.5 134   49 0 (0.63432836 0.36567164) *
##              87) dem_age< 65.5 439  202 1 (0.46013667 0.53986333) *
##        11) dem_affl>=16.5 152   35 1 (0.23026316 0.76973684) *
##     3) dem_age< 44.5 3842 1856 1 (0.48308173 0.51691827)  
##       6) dem_affl< 9.5 2227  854 0 (0.61652447 0.38347553)  
##        12) dem_gender_U>=0.5 361   50 0 (0.86149584 0.13850416) *
##        13) dem_gender_U< 0.5 1866  804 0 (0.56913183 0.43086817)  
##          26) dem_gender_M>=0.5 540  145 0 (0.73148148 0.26851852) *
##          27) dem_gender_M< 0.5 1326  659 0 (0.50301659 0.49698341)  
##            54) dem_affl< 7.5 685  281 0 (0.58978102 0.41021898) *
##            55) dem_affl>=7.5 641  263 1 (0.41029641 0.58970359)  
##             110) dem_age>=39.5 222   98 0 (0.55855856 0.44144144) *
##             111) dem_age< 39.5 419  139 1 (0.33174224 0.66825776) *
##       7) dem_affl>=9.5 1615  483 1 (0.29907121 0.70092879)  
##        14) dem_affl< 14.5 1242  447 1 (0.35990338 0.64009662)  
##          28) dem_gender_U>=0.5 143   49 0 (0.65734266 0.34265734) *
##          29) dem_gender_U< 0.5 1099  353 1 (0.32120109 0.67879891)  
##            58) dem_gender_M>=0.5 288  137 0 (0.52430556 0.47569444)  
##             116) dem_affl< 10.5 93   34 0 (0.63440860 0.36559140) *
##             117) dem_affl>=10.5 195   92 1 (0.47179487 0.52820513) *
##            59) dem_gender_M< 0.5 811  202 1 (0.24907522 0.75092478) *
##        15) dem_affl>=14.5 373   36 1 (0.09651475 0.90348525) *
options(scipen = 0)

rpart.plot(org_tree2$fit, roundint=FALSE, extra=3)

4.2 Logistic Regression

4.2.1 full model

logistic_glm <-logistic_reg(mode = "classification") %>%
                  set_engine("glm") %>%
                  fit(target_buy ~ ., data = bake_train)

tidy(logistic_glm) %>%
  mutate_at(c("estimate", "std.error", "statistic", "p.value"),round, 4)

4.2.2 Stepwise Model

steplog <- glm(target_buy ~ ., data = bake_train, family=binomial(link="logit"))
step <- stepAIC(steplog, direction="both")
## Start:  AIC=13581.73
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_reg_South.West + dem_tv_reg_C.Scotland + dem_tv_reg_East + 
##     dem_tv_reg_London + dem_tv_reg_Midlands + dem_tv_reg_N.East + 
##     dem_tv_reg_N.Scot + dem_tv_reg_N.West + dem_tv_reg_S...S.East + 
##     dem_tv_reg_S.West + dem_tv_reg_Ulster + dem_tv_reg_Wales...West + 
##     dem_tv_reg_Yorkshire + prom_class_Platinum + prom_class_Silver + 
##     prom_class_Tin
## 
## 
## Step:  AIC=13581.73
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_reg_South.West + dem_tv_reg_C.Scotland + dem_tv_reg_East + 
##     dem_tv_reg_London + dem_tv_reg_Midlands + dem_tv_reg_N.East + 
##     dem_tv_reg_N.Scot + dem_tv_reg_N.West + dem_tv_reg_S...S.East + 
##     dem_tv_reg_S.West + dem_tv_reg_Ulster + dem_tv_reg_Wales...West + 
##     prom_class_Platinum + prom_class_Silver + prom_class_Tin
## 
## 
## Step:  AIC=13581.73
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_reg_South.West + dem_tv_reg_C.Scotland + dem_tv_reg_East + 
##     dem_tv_reg_London + dem_tv_reg_Midlands + dem_tv_reg_N.East + 
##     dem_tv_reg_N.Scot + dem_tv_reg_N.West + dem_tv_reg_S...S.East + 
##     dem_tv_reg_S.West + dem_tv_reg_Ulster + prom_class_Platinum + 
##     prom_class_Silver + prom_class_Tin
## 
## 
## Step:  AIC=13581.73
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_reg_South.West + dem_tv_reg_C.Scotland + dem_tv_reg_East + 
##     dem_tv_reg_London + dem_tv_reg_Midlands + dem_tv_reg_N.East + 
##     dem_tv_reg_N.Scot + dem_tv_reg_N.West + dem_tv_reg_S...S.East + 
##     dem_tv_reg_Ulster + prom_class_Platinum + prom_class_Silver + 
##     prom_class_Tin
## 
## 
## Step:  AIC=13581.73
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_reg_South.West + dem_tv_reg_C.Scotland + dem_tv_reg_East + 
##     dem_tv_reg_London + dem_tv_reg_Midlands + dem_tv_reg_N.East + 
##     dem_tv_reg_N.Scot + dem_tv_reg_N.West + dem_tv_reg_Ulster + 
##     prom_class_Platinum + prom_class_Silver + prom_class_Tin
## 
##                         Df Deviance   AIC
## - dem_tv_reg_East        1    13526 13580
## - dem_reg_South.West     1    13526 13580
## - prom_class_Tin         1    13526 13580
## - dem_tv_reg_C.Scotland  1    13526 13580
## - dem_tv_reg_London      1    13526 13580
## - prom_class_Platinum    1    13526 13580
## - dem_tv_reg_N.Scot      1    13526 13580
## - dem_reg_Scottish       1    13526 13580
## - dem_tv_reg_Ulster      1    13526 13580
## - dem_cluster_group_U    1    13526 13580
## - prom_spend             1    13526 13580
## - prom_time              1    13526 13580
## - prom_class_Silver      1    13526 13580
## - dem_reg_South.East     1    13526 13580
## - dem_cluster_group_B    1    13527 13581
## - dem_tv_reg_N.East      1    13527 13581
## - dem_tv_reg_Midlands    1    13527 13581
## - dem_tv_reg_N.West      1    13527 13581
## - dem_cluster_group_D    1    13527 13581
## <none>                        13526 13582
## - dem_cluster_group_E    1    13528 13582
## - dem_cluster_group_F    1    13530 13584
## - dem_cluster_group_C    1    13530 13584
## - dem_reg_North          1    13530 13584
## - dem_gender_M           1    13870 13924
## - dem_gender_U           1    14217 14271
## - dem_age                1    14302 14356
## - dem_affl               1    15008 15062
## 
## Step:  AIC=13579.73
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_reg_South.West + dem_tv_reg_C.Scotland + dem_tv_reg_London + 
##     dem_tv_reg_Midlands + dem_tv_reg_N.East + dem_tv_reg_N.Scot + 
##     dem_tv_reg_N.West + dem_tv_reg_Ulster + prom_class_Platinum + 
##     prom_class_Silver + prom_class_Tin
## 
##                           Df Deviance   AIC
## - prom_class_Tin           1    13526 13578
## - dem_tv_reg_C.Scotland    1    13526 13578
## - dem_reg_South.West       1    13526 13578
## - dem_tv_reg_London        1    13526 13578
## - prom_class_Platinum      1    13526 13578
## - dem_tv_reg_N.Scot        1    13526 13578
## - dem_reg_Scottish         1    13526 13578
## - dem_cluster_group_U      1    13526 13578
## - dem_tv_reg_Ulster        1    13526 13578
## - prom_spend               1    13526 13578
## - prom_time                1    13526 13578
## - prom_class_Silver        1    13526 13578
## - dem_reg_South.East       1    13527 13579
## - dem_cluster_group_B      1    13527 13579
## - dem_tv_reg_N.East        1    13527 13579
## - dem_tv_reg_N.West        1    13527 13579
## - dem_cluster_group_D      1    13528 13580
## <none>                          13526 13580
## - dem_tv_reg_Midlands      1    13528 13580
## - dem_cluster_group_E      1    13528 13580
## + dem_tv_reg_East          1    13526 13582
## + dem_tv_reg_Wales...West  1    13526 13582
## - dem_cluster_group_F      1    13530 13582
## - dem_cluster_group_C      1    13530 13582
## - dem_reg_North            1    13532 13584
## - dem_gender_M             1    13870 13922
## - dem_gender_U             1    14217 14269
## - dem_age                  1    14302 14354
## - dem_affl                 1    15008 15060
## 
## Step:  AIC=13577.74
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_reg_South.West + dem_tv_reg_C.Scotland + dem_tv_reg_London + 
##     dem_tv_reg_Midlands + dem_tv_reg_N.East + dem_tv_reg_N.Scot + 
##     dem_tv_reg_N.West + dem_tv_reg_Ulster + prom_class_Platinum + 
##     prom_class_Silver
## 
##                           Df Deviance   AIC
## - dem_tv_reg_C.Scotland    1    13526 13576
## - dem_reg_South.West       1    13526 13576
## - dem_tv_reg_London        1    13526 13576
## - prom_class_Platinum      1    13526 13576
## - dem_tv_reg_N.Scot        1    13526 13576
## - dem_reg_Scottish         1    13526 13576
## - dem_cluster_group_U      1    13526 13576
## - dem_tv_reg_Ulster        1    13526 13576
## - prom_spend               1    13526 13576
## - prom_time                1    13526 13576
## - prom_class_Silver        1    13527 13577
## - dem_reg_South.East       1    13527 13577
## - dem_cluster_group_B      1    13527 13577
## - dem_tv_reg_N.East        1    13527 13577
## - dem_tv_reg_N.West        1    13527 13577
## - dem_cluster_group_D      1    13528 13578
## <none>                          13526 13578
## - dem_tv_reg_Midlands      1    13528 13578
## - dem_cluster_group_E      1    13528 13578
## + prom_class_Tin           1    13526 13580
## + dem_tv_reg_East          1    13526 13580
## + dem_tv_reg_Wales...West  1    13526 13580
## - dem_cluster_group_F      1    13530 13580
## - dem_cluster_group_C      1    13530 13580
## - dem_reg_North            1    13532 13582
## - dem_gender_M             1    13870 13920
## - dem_gender_U             1    14217 14267
## - dem_age                  1    14333 14383
## - dem_affl                 1    15008 15058
## 
## Step:  AIC=13575.75
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_reg_South.West + dem_tv_reg_London + dem_tv_reg_Midlands + 
##     dem_tv_reg_N.East + dem_tv_reg_N.Scot + dem_tv_reg_N.West + 
##     dem_tv_reg_Ulster + prom_class_Platinum + prom_class_Silver
## 
##                           Df Deviance   AIC
## - dem_reg_South.West       1    13526 13574
## - dem_tv_reg_London        1    13526 13574
## - prom_class_Platinum      1    13526 13574
## - dem_cluster_group_U      1    13526 13574
## - dem_tv_reg_N.Scot        1    13526 13574
## - dem_tv_reg_Ulster        1    13526 13574
## - prom_spend               1    13526 13574
## - dem_reg_Scottish         1    13526 13574
## - prom_time                1    13526 13574
## - dem_reg_South.East       1    13527 13575
## - prom_class_Silver        1    13527 13575
## - dem_cluster_group_B      1    13527 13575
## - dem_tv_reg_N.East        1    13527 13575
## - dem_tv_reg_N.West        1    13527 13575
## - dem_cluster_group_D      1    13528 13576
## <none>                          13526 13576
## - dem_tv_reg_Midlands      1    13528 13576
## - dem_cluster_group_E      1    13528 13576
## + dem_tv_reg_C.Scotland    1    13526 13578
## + prom_class_Tin           1    13526 13578
## + dem_tv_reg_East          1    13526 13578
## + dem_tv_reg_Wales...West  1    13526 13578
## - dem_cluster_group_F      1    13530 13578
## - dem_cluster_group_C      1    13530 13578
## - dem_reg_North            1    13532 13580
## - dem_gender_M             1    13870 13918
## - dem_gender_U             1    14217 14265
## - dem_age                  1    14333 14381
## - dem_affl                 1    15008 15056
## 
## Step:  AIC=13573.77
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_tv_reg_London + dem_tv_reg_Midlands + dem_tv_reg_N.East + 
##     dem_tv_reg_N.Scot + dem_tv_reg_N.West + dem_tv_reg_Ulster + 
##     prom_class_Platinum + prom_class_Silver
## 
##                           Df Deviance   AIC
## - dem_tv_reg_London        1    13526 13572
## - prom_class_Platinum      1    13526 13572
## - dem_cluster_group_U      1    13526 13572
## - dem_tv_reg_N.Scot        1    13526 13572
## - dem_tv_reg_Ulster        1    13526 13572
## - prom_spend               1    13526 13572
## - dem_reg_Scottish         1    13526 13572
## - prom_time                1    13526 13572
## - prom_class_Silver        1    13527 13573
## - dem_reg_South.East       1    13527 13573
## - dem_cluster_group_B      1    13527 13573
## - dem_tv_reg_N.East        1    13527 13573
## - dem_tv_reg_N.West        1    13527 13573
## - dem_cluster_group_D      1    13528 13574
## <none>                          13526 13574
## - dem_tv_reg_Midlands      1    13528 13574
## - dem_cluster_group_E      1    13528 13574
## + dem_reg_South.West       1    13526 13576
## + dem_tv_reg_S.West        1    13526 13576
## + dem_tv_reg_C.Scotland    1    13526 13576
## + prom_class_Tin           1    13526 13576
## + dem_tv_reg_East          1    13526 13576
## + dem_tv_reg_Wales...West  1    13526 13576
## - dem_cluster_group_F      1    13530 13576
## - dem_cluster_group_C      1    13530 13576
## - dem_reg_North            1    13532 13578
## - dem_gender_M             1    13870 13916
## - dem_gender_U             1    14217 14263
## - dem_age                  1    14334 14380
## - dem_affl                 1    15008 15054
## 
## Step:  AIC=13571.79
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_tv_reg_Midlands + dem_tv_reg_N.East + dem_tv_reg_N.Scot + 
##     dem_tv_reg_N.West + dem_tv_reg_Ulster + prom_class_Platinum + 
##     prom_class_Silver
## 
##                           Df Deviance   AIC
## - prom_class_Platinum      1    13526 13570
## - dem_cluster_group_U      1    13526 13570
## - dem_tv_reg_N.Scot        1    13526 13570
## - dem_tv_reg_Ulster        1    13526 13570
## - prom_spend               1    13526 13570
## - dem_reg_Scottish         1    13526 13570
## - prom_time                1    13526 13570
## - prom_class_Silver        1    13527 13571
## - dem_cluster_group_B      1    13527 13571
## - dem_tv_reg_N.East        1    13527 13571
## - dem_tv_reg_N.West        1    13527 13571
## - dem_cluster_group_D      1    13528 13572
## - dem_reg_South.East       1    13528 13572
## <none>                          13526 13572
## - dem_tv_reg_Midlands      1    13528 13572
## - dem_cluster_group_E      1    13528 13572
## + dem_tv_reg_London        1    13526 13574
## + dem_tv_reg_S...S.East    1    13526 13574
## + dem_reg_South.West       1    13526 13574
## + dem_tv_reg_S.West        1    13526 13574
## + dem_tv_reg_C.Scotland    1    13526 13574
## + prom_class_Tin           1    13526 13574
## + dem_tv_reg_East          1    13526 13574
## + dem_tv_reg_Wales...West  1    13526 13574
## - dem_cluster_group_F      1    13530 13574
## - dem_cluster_group_C      1    13530 13574
## - dem_reg_North            1    13532 13576
## - dem_gender_M             1    13870 13914
## - dem_gender_U             1    14217 14261
## - dem_age                  1    14337 14381
## - dem_affl                 1    15008 15052
## 
## Step:  AIC=13569.83
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_cluster_group_U + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_Scottish + dem_reg_South.East + 
##     dem_tv_reg_Midlands + dem_tv_reg_N.East + dem_tv_reg_N.Scot + 
##     dem_tv_reg_N.West + dem_tv_reg_Ulster + prom_class_Silver
## 
##                           Df Deviance   AIC
## - dem_cluster_group_U      1    13526 13568
## - dem_tv_reg_N.Scot        1    13526 13568
## - dem_tv_reg_Ulster        1    13526 13568
## - dem_reg_Scottish         1    13526 13568
## - prom_time                1    13526 13568
## - prom_spend               1    13526 13568
## - prom_class_Silver        1    13527 13569
## - dem_cluster_group_B      1    13527 13569
## - dem_tv_reg_N.East        1    13527 13569
## - dem_tv_reg_N.West        1    13527 13569
## - dem_cluster_group_D      1    13528 13570
## - dem_reg_South.East       1    13528 13570
## <none>                          13526 13570
## - dem_tv_reg_Midlands      1    13528 13570
## - dem_cluster_group_E      1    13528 13570
## + prom_class_Platinum      1    13526 13572
## + prom_class_Tin           1    13526 13572
## + dem_tv_reg_London        1    13526 13572
## + dem_tv_reg_S...S.East    1    13526 13572
## + dem_reg_South.West       1    13526 13572
## + dem_tv_reg_S.West        1    13526 13572
## + dem_tv_reg_C.Scotland    1    13526 13572
## + dem_tv_reg_East          1    13526 13572
## + dem_tv_reg_Wales...West  1    13526 13572
## - dem_cluster_group_F      1    13530 13572
## - dem_cluster_group_C      1    13530 13572
## - dem_reg_North            1    13532 13574
## - dem_gender_M             1    13870 13912
## - dem_gender_U             1    14217 14259
## - dem_age                  1    14346 14388
## - dem_affl                 1    15008 15050
## 
## Step:  AIC=13567.99
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_gender_M + dem_gender_U + dem_reg_North + 
##     dem_reg_Scottish + dem_reg_South.East + dem_tv_reg_Midlands + 
##     dem_tv_reg_N.East + dem_tv_reg_N.Scot + dem_tv_reg_N.West + 
##     dem_tv_reg_Ulster + prom_class_Silver
## 
##                           Df Deviance   AIC
## - dem_tv_reg_N.Scot        1    13526 13566
## - dem_tv_reg_Ulster        1    13526 13566
## - dem_reg_Scottish         1    13526 13566
## - prom_time                1    13526 13566
## - prom_spend               1    13527 13567
## - prom_class_Silver        1    13527 13567
## - dem_cluster_group_B      1    13527 13567
## - dem_tv_reg_N.East        1    13527 13567
## - dem_tv_reg_N.West        1    13528 13568
## - dem_cluster_group_D      1    13528 13568
## - dem_reg_South.East       1    13528 13568
## <none>                          13526 13568
## - dem_tv_reg_Midlands      1    13528 13568
## - dem_cluster_group_E      1    13528 13568
## + dem_cluster_group_U      1    13526 13570
## + prom_class_Platinum      1    13526 13570
## + prom_class_Tin           1    13526 13570
## + dem_tv_reg_London        1    13526 13570
## + dem_tv_reg_S...S.East    1    13526 13570
## - dem_cluster_group_F      1    13530 13570
## + dem_reg_South.West       1    13526 13570
## + dem_tv_reg_S.West        1    13526 13570
## + dem_tv_reg_C.Scotland    1    13526 13570
## + dem_tv_reg_East          1    13526 13570
## + dem_tv_reg_Wales...West  1    13526 13570
## - dem_cluster_group_C      1    13530 13570
## - dem_reg_North            1    13532 13572
## - dem_gender_M             1    13870 13910
## - dem_gender_U             1    14218 14258
## - dem_age                  1    14348 14388
## - dem_affl                 1    15008 15048
## 
## Step:  AIC=13566.15
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_gender_M + dem_gender_U + dem_reg_North + 
##     dem_reg_Scottish + dem_reg_South.East + dem_tv_reg_Midlands + 
##     dem_tv_reg_N.East + dem_tv_reg_N.West + dem_tv_reg_Ulster + 
##     prom_class_Silver
## 
##                           Df Deviance   AIC
## - dem_tv_reg_Ulster        1    13526 13564
## - prom_time                1    13526 13564
## - dem_reg_Scottish         1    13527 13565
## - prom_spend               1    13527 13565
## - prom_class_Silver        1    13527 13565
## - dem_cluster_group_B      1    13527 13565
## - dem_tv_reg_N.East        1    13527 13565
## - dem_tv_reg_N.West        1    13528 13566
## - dem_cluster_group_D      1    13528 13566
## - dem_reg_South.East       1    13528 13566
## <none>                          13526 13566
## - dem_tv_reg_Midlands      1    13528 13566
## - dem_cluster_group_E      1    13529 13567
## + dem_tv_reg_N.Scot        1    13526 13568
## + dem_cluster_group_U      1    13526 13568
## + dem_tv_reg_C.Scotland    1    13526 13568
## + prom_class_Platinum      1    13526 13568
## - dem_cluster_group_F      1    13530 13568
## + prom_class_Tin           1    13526 13568
## + dem_tv_reg_London        1    13526 13568
## + dem_tv_reg_S...S.East    1    13526 13568
## + dem_reg_South.West       1    13526 13568
## + dem_tv_reg_S.West        1    13526 13568
## + dem_tv_reg_East          1    13526 13568
## + dem_tv_reg_Wales...West  1    13526 13568
## - dem_cluster_group_C      1    13530 13568
## - dem_reg_North            1    13532 13570
## - dem_gender_M             1    13871 13909
## - dem_gender_U             1    14218 14256
## - dem_age                  1    14348 14386
## - dem_affl                 1    15008 15046
## 
## Step:  AIC=13564.32
## target_buy ~ dem_affl + dem_age + prom_spend + prom_time + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_gender_M + dem_gender_U + dem_reg_North + 
##     dem_reg_Scottish + dem_reg_South.East + dem_tv_reg_Midlands + 
##     dem_tv_reg_N.East + dem_tv_reg_N.West + prom_class_Silver
## 
##                           Df Deviance   AIC
## - prom_time                1    13527 13563
## - dem_reg_Scottish         1    13527 13563
## - prom_spend               1    13527 13563
## - prom_class_Silver        1    13527 13563
## - dem_cluster_group_B      1    13527 13563
## - dem_tv_reg_N.East        1    13528 13564
## - dem_tv_reg_N.West        1    13528 13564
## - dem_cluster_group_D      1    13528 13564
## - dem_reg_South.East       1    13528 13564
## - dem_tv_reg_Midlands      1    13528 13564
## <none>                          13526 13564
## - dem_cluster_group_E      1    13529 13565
## + dem_tv_reg_Ulster        1    13526 13566
## + dem_cluster_group_U      1    13526 13566
## + dem_tv_reg_N.Scot        1    13526 13566
## + dem_tv_reg_C.Scotland    1    13526 13566
## + prom_class_Platinum      1    13526 13566
## + dem_tv_reg_East          1    13526 13566
## + prom_class_Tin           1    13526 13566
## + dem_tv_reg_London        1    13526 13566
## + dem_tv_reg_S...S.East    1    13526 13566
## + dem_tv_reg_Wales...West  1    13526 13566
## + dem_reg_South.West       1    13526 13566
## + dem_tv_reg_S.West        1    13526 13566
## - dem_cluster_group_F      1    13530 13566
## - dem_cluster_group_C      1    13530 13566
## - dem_reg_North            1    13532 13568
## - dem_gender_M             1    13871 13907
## - dem_gender_U             1    14218 14254
## - dem_age                  1    14348 14384
## - dem_affl                 1    15009 15045
## 
## Step:  AIC=13562.65
## target_buy ~ dem_affl + dem_age + prom_spend + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_gender_M + dem_gender_U + dem_reg_North + 
##     dem_reg_Scottish + dem_reg_South.East + dem_tv_reg_Midlands + 
##     dem_tv_reg_N.East + dem_tv_reg_N.West + prom_class_Silver
## 
##                           Df Deviance   AIC
## - dem_reg_Scottish         1    13527 13561
## - prom_spend               1    13527 13561
## - prom_class_Silver        1    13528 13562
## - dem_cluster_group_B      1    13528 13562
## - dem_tv_reg_N.East        1    13528 13562
## - dem_tv_reg_N.West        1    13528 13562
## - dem_cluster_group_D      1    13528 13562
## - dem_reg_South.East       1    13528 13562
## - dem_tv_reg_Midlands      1    13529 13563
## <none>                          13527 13563
## - dem_cluster_group_E      1    13529 13563
## + prom_time                1    13526 13564
## + dem_tv_reg_Ulster        1    13526 13564
## + dem_cluster_group_U      1    13526 13564
## + dem_tv_reg_N.Scot        1    13526 13564
## + dem_tv_reg_C.Scotland    1    13526 13564
## - dem_cluster_group_F      1    13531 13565
## + prom_class_Platinum      1    13527 13565
## + dem_tv_reg_East          1    13527 13565
## + dem_tv_reg_London        1    13527 13565
## + dem_tv_reg_S...S.East    1    13527 13565
## + prom_class_Tin           1    13527 13565
## + dem_tv_reg_Wales...West  1    13527 13565
## + dem_reg_South.West       1    13527 13565
## + dem_tv_reg_S.West        1    13527 13565
## - dem_cluster_group_C      1    13531 13565
## - dem_reg_North            1    13533 13567
## - dem_gender_M             1    13871 13905
## - dem_gender_U             1    14218 14252
## - dem_age                  1    14374 14408
## - dem_affl                 1    15009 15043
## 
## Step:  AIC=13561.14
## target_buy ~ dem_affl + dem_age + prom_spend + dem_cluster_group_B + 
##     dem_cluster_group_C + dem_cluster_group_D + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_gender_M + dem_gender_U + dem_reg_North + 
##     dem_reg_South.East + dem_tv_reg_Midlands + dem_tv_reg_N.East + 
##     dem_tv_reg_N.West + prom_class_Silver
## 
##                           Df Deviance   AIC
## - prom_spend               1    13528 13560
## - prom_class_Silver        1    13528 13560
## - dem_cluster_group_B      1    13528 13560
## - dem_tv_reg_N.East        1    13528 13560
## - dem_reg_South.East       1    13528 13560
## - dem_tv_reg_N.West        1    13529 13561
## - dem_tv_reg_Midlands      1    13529 13561
## - dem_cluster_group_D      1    13529 13561
## <none>                          13527 13561
## - dem_cluster_group_E      1    13530 13562
## + dem_reg_Scottish         1    13527 13563
## + dem_tv_reg_N.Scot        1    13527 13563
## + prom_time                1    13527 13563
## + dem_cluster_group_U      1    13527 13563
## + dem_tv_reg_East          1    13527 13563
## + dem_tv_reg_Wales...West  1    13527 13563
## + dem_tv_reg_Ulster        1    13527 13563
## + dem_tv_reg_C.Scotland    1    13527 13563
## + prom_class_Platinum      1    13527 13563
## + dem_tv_reg_London        1    13527 13563
## + dem_tv_reg_S...S.East    1    13527 13563
## + dem_reg_South.West       1    13527 13563
## + dem_tv_reg_S.West        1    13527 13563
## + prom_class_Tin           1    13527 13563
## - dem_cluster_group_F      1    13531 13563
## - dem_cluster_group_C      1    13532 13564
## - dem_reg_North            1    13533 13565
## - dem_gender_M             1    13872 13904
## - dem_gender_U             1    14218 14250
## - dem_age                  1    14374 14406
## - dem_affl                 1    15010 15042
## 
## Step:  AIC=13559.86
## target_buy ~ dem_affl + dem_age + dem_cluster_group_B + dem_cluster_group_C + 
##     dem_cluster_group_D + dem_cluster_group_E + dem_cluster_group_F + 
##     dem_gender_M + dem_gender_U + dem_reg_North + dem_reg_South.East + 
##     dem_tv_reg_Midlands + dem_tv_reg_N.East + dem_tv_reg_N.West + 
##     prom_class_Silver
## 
##                           Df Deviance   AIC
## - prom_class_Silver        1    13528 13558
## - dem_cluster_group_B      1    13529 13559
## - dem_reg_South.East       1    13529 13559
## - dem_tv_reg_N.East        1    13529 13559
## - dem_tv_reg_Midlands      1    13529 13559
## - dem_tv_reg_N.West        1    13529 13559
## - dem_cluster_group_D      1    13530 13560
## <none>                          13528 13560
## - dem_cluster_group_E      1    13530 13560
## + prom_spend               1    13527 13561
## + dem_reg_Scottish         1    13527 13561
## + prom_class_Platinum      1    13527 13561
## + dem_tv_reg_N.Scot        1    13527 13561
## + prom_time                1    13528 13562
## + prom_class_Tin           1    13528 13562
## + dem_cluster_group_U      1    13528 13562
## + dem_tv_reg_East          1    13528 13562
## + dem_tv_reg_Wales...West  1    13528 13562
## + dem_tv_reg_Ulster        1    13528 13562
## + dem_tv_reg_C.Scotland    1    13528 13562
## + dem_tv_reg_London        1    13528 13562
## + dem_tv_reg_S...S.East    1    13528 13562
## + dem_reg_South.West       1    13528 13562
## + dem_tv_reg_S.West        1    13528 13562
## - dem_cluster_group_F      1    13532 13562
## - dem_cluster_group_C      1    13532 13562
## - dem_reg_North            1    13534 13564
## - dem_gender_M             1    13872 13902
## - dem_gender_U             1    14219 14249
## - dem_age                  1    14458 14488
## - dem_affl                 1    15010 15040
## 
## Step:  AIC=13558.45
## target_buy ~ dem_affl + dem_age + dem_cluster_group_B + dem_cluster_group_C + 
##     dem_cluster_group_D + dem_cluster_group_E + dem_cluster_group_F + 
##     dem_gender_M + dem_gender_U + dem_reg_North + dem_reg_South.East + 
##     dem_tv_reg_Midlands + dem_tv_reg_N.East + dem_tv_reg_N.West
## 
##                           Df Deviance   AIC
## - dem_cluster_group_B      1    13530 13558
## - dem_reg_South.East       1    13530 13558
## - dem_tv_reg_N.East        1    13530 13558
## - dem_tv_reg_Midlands      1    13530 13558
## - dem_tv_reg_N.West        1    13530 13558
## - dem_cluster_group_D      1    13530 13558
## <none>                          13528 13558
## - dem_cluster_group_E      1    13531 13559
## + prom_class_Tin           1    13528 13560
## + prom_class_Silver        1    13528 13560
## + dem_reg_Scottish         1    13528 13560
## + dem_tv_reg_N.Scot        1    13528 13560
## + prom_spend               1    13528 13560
## + prom_class_Platinum      1    13528 13560
## + prom_time                1    13528 13560
## + dem_cluster_group_U      1    13528 13560
## + dem_tv_reg_East          1    13528 13560
## + dem_tv_reg_Wales...West  1    13528 13560
## + dem_tv_reg_Ulster        1    13528 13560
## + dem_tv_reg_C.Scotland    1    13528 13560
## + dem_tv_reg_London        1    13528 13560
## + dem_tv_reg_S...S.East    1    13528 13560
## + dem_reg_South.West       1    13528 13560
## + dem_tv_reg_S.West        1    13528 13560
## - dem_cluster_group_F      1    13533 13561
## - dem_cluster_group_C      1    13533 13561
## - dem_reg_North            1    13534 13562
## - dem_gender_M             1    13873 13901
## - dem_gender_U             1    14219 14247
## - dem_age                  1    14458 14486
## - dem_affl                 1    15010 15038
## 
## Step:  AIC=13557.52
## target_buy ~ dem_affl + dem_age + dem_cluster_group_C + dem_cluster_group_D + 
##     dem_cluster_group_E + dem_cluster_group_F + dem_gender_M + 
##     dem_gender_U + dem_reg_North + dem_reg_South.East + dem_tv_reg_Midlands + 
##     dem_tv_reg_N.East + dem_tv_reg_N.West
## 
##                           Df Deviance   AIC
## - dem_cluster_group_D      1    13530 13556
## - dem_tv_reg_N.East        1    13531 13557
## - dem_reg_South.East       1    13531 13557
## - dem_tv_reg_Midlands      1    13531 13557
## - dem_tv_reg_N.West        1    13531 13557
## - dem_cluster_group_E      1    13531 13557
## <none>                          13530 13558
## + dem_cluster_group_B      1    13528 13558
## + prom_class_Tin           1    13529 13559
## + prom_class_Silver        1    13529 13559
## + dem_reg_Scottish         1    13529 13559
## - dem_cluster_group_F      1    13533 13559
## + prom_spend               1    13529 13559
## + dem_tv_reg_N.Scot        1    13529 13559
## + prom_class_Platinum      1    13529 13559
## + prom_time                1    13529 13559
## + dem_tv_reg_East          1    13529 13559
## + dem_tv_reg_Wales...West  1    13529 13559
## + dem_tv_reg_Ulster        1    13529 13559
## - dem_cluster_group_C      1    13533 13559
## + dem_tv_reg_C.Scotland    1    13529 13559
## + dem_tv_reg_London        1    13530 13560
## + dem_tv_reg_S...S.East    1    13530 13560
## + dem_cluster_group_U      1    13530 13560
## + dem_reg_South.West       1    13530 13560
## + dem_tv_reg_S.West        1    13530 13560
## - dem_reg_North            1    13535 13561
## - dem_gender_M             1    13874 13900
## - dem_gender_U             1    14220 14246
## - dem_age                  1    14458 14484
## - dem_affl                 1    15013 15039
## 
## Step:  AIC=13556.24
## target_buy ~ dem_affl + dem_age + dem_cluster_group_C + dem_cluster_group_E + 
##     dem_cluster_group_F + dem_gender_M + dem_gender_U + dem_reg_North + 
##     dem_reg_South.East + dem_tv_reg_Midlands + dem_tv_reg_N.East + 
##     dem_tv_reg_N.West
## 
##                           Df Deviance   AIC
## - dem_cluster_group_E      1    13531 13555
## - dem_tv_reg_N.East        1    13532 13556
## - dem_tv_reg_Midlands      1    13532 13556
## - dem_tv_reg_N.West        1    13532 13556
## - dem_reg_South.East       1    13532 13556
## <none>                          13530 13556
## - dem_cluster_group_F      1    13533 13557
## - dem_cluster_group_C      1    13533 13557
## + prom_class_Tin           1    13530 13558
## + dem_cluster_group_D      1    13530 13558
## + prom_class_Silver        1    13530 13558
## + dem_reg_Scottish         1    13530 13558
## + prom_spend               1    13530 13558
## + dem_tv_reg_N.Scot        1    13530 13558
## + prom_class_Platinum      1    13530 13558
## + prom_time                1    13530 13558
## + dem_tv_reg_East          1    13530 13558
## + dem_tv_reg_Wales...West  1    13530 13558
## + dem_tv_reg_Ulster        1    13530 13558
## + dem_tv_reg_C.Scotland    1    13530 13558
## + dem_tv_reg_London        1    13530 13558
## + dem_tv_reg_S...S.East    1    13530 13558
## + dem_cluster_group_U      1    13530 13558
## + dem_cluster_group_B      1    13530 13558
## + dem_reg_South.West       1    13530 13558
## + dem_tv_reg_S.West        1    13530 13558
## - dem_reg_North            1    13536 13560
## - dem_gender_M             1    13875 13899
## - dem_gender_U             1    14222 14246
## - dem_age                  1    14477 14501
## - dem_affl                 1    15014 15038
## 
## Step:  AIC=13555.26
## target_buy ~ dem_affl + dem_age + dem_cluster_group_C + dem_cluster_group_F + 
##     dem_gender_M + dem_gender_U + dem_reg_North + dem_reg_South.East + 
##     dem_tv_reg_Midlands + dem_tv_reg_N.East + dem_tv_reg_N.West
## 
##                           Df Deviance   AIC
## - dem_tv_reg_N.East        1    13532 13554
## - dem_tv_reg_N.West        1    13533 13555
## - dem_tv_reg_Midlands      1    13533 13555
## - dem_reg_South.East       1    13533 13555
## <none>                          13531 13555
## - dem_cluster_group_F      1    13533 13555
## - dem_cluster_group_C      1    13534 13556
## + dem_cluster_group_E      1    13530 13556
## + prom_class_Tin           1    13530 13556
## + dem_reg_Scottish         1    13531 13557
## + prom_class_Silver        1    13531 13557
## + prom_spend               1    13531 13557
## + dem_tv_reg_N.Scot        1    13531 13557
## + prom_class_Platinum      1    13531 13557
## + prom_time                1    13531 13557
## + dem_tv_reg_East          1    13531 13557
## + dem_cluster_group_D      1    13531 13557
## + dem_tv_reg_C.Scotland    1    13531 13557
## + dem_tv_reg_Wales...West  1    13531 13557
## + dem_tv_reg_Ulster        1    13531 13557
## + dem_tv_reg_London        1    13531 13557
## + dem_tv_reg_S...S.East    1    13531 13557
## + dem_cluster_group_B      1    13531 13557
## + dem_cluster_group_U      1    13531 13557
## + dem_reg_South.West       1    13531 13557
## + dem_tv_reg_S.West        1    13531 13557
## - dem_reg_North            1    13537 13559
## - dem_gender_M             1    13876 13898
## - dem_gender_U             1    14223 14245
## - dem_age                  1    14482 14504
## - dem_affl                 1    15017 15039
## 
## Step:  AIC=13554.47
## target_buy ~ dem_affl + dem_age + dem_cluster_group_C + dem_cluster_group_F + 
##     dem_gender_M + dem_gender_U + dem_reg_North + dem_reg_South.East + 
##     dem_tv_reg_Midlands + dem_tv_reg_N.West
## 
##                           Df Deviance   AIC
## - dem_tv_reg_N.West        1    13533 13553
## - dem_tv_reg_Midlands      1    13534 13554
## - dem_reg_South.East       1    13534 13554
## <none>                          13532 13554
## - dem_cluster_group_F      1    13535 13555
## - dem_cluster_group_C      1    13535 13555
## + dem_tv_reg_N.East        1    13531 13555
## + dem_tv_reg_Yorkshire     1    13531 13555
## + dem_cluster_group_E      1    13532 13556
## + prom_class_Tin           1    13532 13556
## + dem_reg_Scottish         1    13532 13556
## + prom_class_Silver        1    13532 13556
## + prom_spend               1    13532 13556
## + dem_tv_reg_N.Scot        1    13532 13556
## + prom_class_Platinum      1    13532 13556
## + prom_time                1    13532 13556
## + dem_tv_reg_East          1    13532 13556
## + dem_cluster_group_D      1    13532 13556
## + dem_tv_reg_C.Scotland    1    13532 13556
## + dem_tv_reg_Wales...West  1    13532 13556
## + dem_tv_reg_Ulster        1    13532 13556
## + dem_tv_reg_London        1    13532 13556
## + dem_tv_reg_S...S.East    1    13532 13556
## + dem_cluster_group_B      1    13532 13556
## + dem_cluster_group_U      1    13532 13556
## + dem_reg_South.West       1    13532 13556
## + dem_tv_reg_S.West        1    13532 13556
## - dem_reg_North            1    13537 13557
## - dem_gender_M             1    13876 13896
## - dem_gender_U             1    14224 14244
## - dem_age                  1    14484 14504
## - dem_affl                 1    15017 15037
## 
## Step:  AIC=13553.07
## target_buy ~ dem_affl + dem_age + dem_cluster_group_C + dem_cluster_group_F + 
##     dem_gender_M + dem_gender_U + dem_reg_North + dem_reg_South.East + 
##     dem_tv_reg_Midlands
## 
##                           Df Deviance   AIC
## - dem_tv_reg_Midlands      1    13534 13552
## - dem_reg_South.East       1    13535 13553
## <none>                          13533 13553
## - dem_cluster_group_F      1    13535 13553
## + dem_tv_reg_Yorkshire     1    13531 13553
## - dem_cluster_group_C      1    13536 13554
## + dem_cluster_group_E      1    13532 13554
## + prom_class_Tin           1    13532 13554
## + dem_reg_Scottish         1    13532 13554
## + prom_class_Silver        1    13532 13554
## + dem_tv_reg_N.West        1    13532 13554
## + prom_spend               1    13532 13554
## + dem_tv_reg_N.Scot        1    13533 13555
## + prom_class_Platinum      1    13533 13555
## + dem_tv_reg_N.East        1    13533 13555
## + prom_time                1    13533 13555
## + dem_tv_reg_East          1    13533 13555
## + dem_cluster_group_D      1    13533 13555
## + dem_tv_reg_C.Scotland    1    13533 13555
## + dem_tv_reg_Wales...West  1    13533 13555
## + dem_tv_reg_Ulster        1    13533 13555
## + dem_tv_reg_London        1    13533 13555
## + dem_tv_reg_S...S.East    1    13533 13555
## + dem_cluster_group_B      1    13533 13555
## + dem_reg_South.West       1    13533 13555
## + dem_tv_reg_S.West        1    13533 13555
## + dem_cluster_group_U      1    13533 13555
## - dem_reg_North            1    13537 13555
## - dem_gender_M             1    13877 13895
## - dem_gender_U             1    14225 14243
## - dem_age                  1    14485 14503
## - dem_affl                 1    15017 15035
## 
## Step:  AIC=13552.54
## target_buy ~ dem_affl + dem_age + dem_cluster_group_C + dem_cluster_group_F + 
##     dem_gender_M + dem_gender_U + dem_reg_North + dem_reg_South.East
## 
##                           Df Deviance   AIC
## - dem_reg_South.East       1    13535 13551
## <none>                          13534 13552
## - dem_cluster_group_F      1    13537 13553
## + dem_tv_reg_Yorkshire     1    13533 13553
## + dem_tv_reg_Midlands      1    13533 13553
## - dem_cluster_group_C      1    13537 13553
## - dem_reg_North            1    13538 13554
## + dem_cluster_group_E      1    13534 13554
## + prom_class_Tin           1    13534 13554
## + dem_tv_reg_East          1    13534 13554
## + dem_tv_reg_Wales...West  1    13534 13554
## + prom_class_Silver        1    13534 13554
## + dem_tv_reg_N.West        1    13534 13554
## + prom_spend               1    13534 13554
## + prom_class_Platinum      1    13534 13554
## + dem_tv_reg_N.East        1    13534 13554
## + prom_time                1    13534 13554
## + dem_tv_reg_N.Scot        1    13534 13554
## + dem_reg_South.West       1    13534 13554
## + dem_tv_reg_S.West        1    13534 13554
## + dem_reg_Scottish         1    13534 13554
## + dem_cluster_group_D      1    13534 13554
## + dem_tv_reg_London        1    13534 13554
## + dem_tv_reg_S...S.East    1    13534 13554
## + dem_tv_reg_Ulster        1    13534 13554
## + dem_cluster_group_B      1    13534 13554
## + dem_cluster_group_U      1    13534 13554
## + dem_tv_reg_C.Scotland    1    13534 13554
## - dem_gender_M             1    13878 13894
## - dem_gender_U             1    14226 14242
## - dem_age                  1    14485 14501
## - dem_affl                 1    15019 15035
## 
## Step:  AIC=13551.25
## target_buy ~ dem_affl + dem_age + dem_cluster_group_C + dem_cluster_group_F + 
##     dem_gender_M + dem_gender_U + dem_reg_North
## 
##                           Df Deviance   AIC
## <none>                          13535 13551
## + dem_tv_reg_Yorkshire     1    13534 13552
## - dem_reg_North            1    13538 13552
## - dem_cluster_group_F      1    13538 13552
## - dem_cluster_group_C      1    13538 13552
## + dem_tv_reg_East          1    13534 13552
## + dem_tv_reg_Wales...West  1    13534 13552
## + dem_cluster_group_E      1    13534 13552
## + prom_class_Tin           1    13534 13552
## + dem_reg_South.East       1    13534 13552
## + dem_tv_reg_London        1    13535 13553
## + prom_class_Silver        1    13535 13553
## + dem_tv_reg_N.West        1    13535 13553
## + prom_spend               1    13535 13553
## + dem_tv_reg_Midlands      1    13535 13553
## + prom_class_Platinum      1    13535 13553
## + dem_tv_reg_N.East        1    13535 13553
## + dem_reg_South.West       1    13535 13553
## + dem_tv_reg_S.West        1    13535 13553
## + prom_time                1    13535 13553
## + dem_cluster_group_D      1    13535 13553
## + dem_tv_reg_N.Scot        1    13535 13553
## + dem_cluster_group_B      1    13535 13553
## + dem_tv_reg_C.Scotland    1    13535 13553
## + dem_cluster_group_U      1    13535 13553
## + dem_tv_reg_Ulster        1    13535 13553
## + dem_reg_Scottish         1    13535 13553
## + dem_tv_reg_S...S.East    1    13535 13553
## - dem_gender_M             1    13878 13892
## - dem_gender_U             1    14226 14240
## - dem_age                  1    14486 14500
## - dem_affl                 1    15020 15034
summary(step)
## 
## Call:
## glm(formula = target_buy ~ dem_affl + dem_age + dem_cluster_group_C + 
##     dem_cluster_group_F + dem_gender_M + dem_gender_U + dem_reg_North, 
##     family = binomial(link = "logit"), data = bake_train)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.3983  -0.6869  -0.4235  -0.1328   3.0987  
## 
## Coefficients:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)         -0.256326   0.115836  -2.213   0.0269 *  
## dem_affl             0.248574   0.007093  35.047   <2e-16 ***
## dem_age             -0.052460   0.001784 -29.398   <2e-16 ***
## dem_cluster_group_C  0.084965   0.051965   1.635   0.1020    
## dem_cluster_group_F  0.087976   0.057329   1.535   0.1249    
## dem_gender_M        -0.936243   0.052681 -17.772   <2e-16 ***
## dem_gender_U        -1.739771   0.076589 -22.716   <2e-16 ***
## dem_reg_North       -0.082297   0.054940  -1.498   0.1341    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 17365  on 15555  degrees of freedom
## Residual deviance: 13535  on 15548  degrees of freedom
## AIC: 13551
## 
## Number of Fisher Scoring iterations: 5
## -- Use tidymodel framework to fit and evaulate reduced model
org_steprecipe <- recipe(target_buy ~ dem_affl + dem_age + dem_gender , data = org_train) %>%
  step_medianimpute(all_numeric()) %>%
  prep()
## Warning: `step_medianimpute()` was deprecated in recipes 0.1.16.
## Please use `step_impute_median()` instead.
org_steprecipe
## Data Recipe
## 
## Inputs:
## 
##       role #variables
##    outcome          1
##  predictor          3
## 
## Training data contained 15556 data points and 3262 incomplete rows. 
## 
## Operations:
## 
## Median Imputation for dem_affl, dem_age [trained]
# -- apply new recipe 
bake_steptrain <- bake(org_steprecipe, new_data = org_train)
bake_steptest  <- bake(org_steprecipe, new_data = org_test)

logistic_step1 <-logistic_reg(mode = "classification") %>%
                  set_engine("glm") %>%
                  fit(target_buy ~ ., data = bake_steptrain)

## -- check out your parameter estimates ... 
tidy(logistic_step1) %>%
  mutate_at(c("estimate", "std.error", "statistic", "p.value"),round, 4)

5. Prep for Evaluation

5.1 Decision tree 1

# -- training 
predict(org_tree, bake_train, type = "prob") %>%
  bind_cols(.,predict(org_tree, bake_train)) %>%
  bind_cols(.,bake_train) -> scored_train_tree

head(scored_train_tree)
# -- testing 
predict(org_tree, bake_test, type = "prob") %>%
  bind_cols(.,predict(org_tree, bake_test)) %>%
  bind_cols(.,bake_test) -> scored_test_tree

head(scored_test_tree)

5.2 Decision tree 2

# -- training 
predict(org_tree2, bake_train, type = "prob") %>%
  bind_cols(.,predict(org_tree2, bake_train)) %>%
  bind_cols(.,bake_train) -> scored_train_tree2

head(scored_train_tree2)
# -- testing 
predict(org_tree2, bake_test, type = "prob") %>%
  bind_cols(.,predict(org_tree2, bake_test)) %>%
  bind_cols(.,bake_test) -> scored_test_tree2

head(scored_test_tree2)

5.3 logistic regression full model

# -- training 
predict(logistic_glm, bake_train, type = "prob") %>%
  bind_cols(.,predict(logistic_glm, bake_train)) %>%
  bind_cols(.,bake_train) -> scored_train_glm
## Warning in predict.lm(object, newdata, se.fit, scale = 1, type = if (type == :
## prediction from a rank-deficient fit may be misleading

## Warning in predict.lm(object, newdata, se.fit, scale = 1, type = if (type == :
## prediction from a rank-deficient fit may be misleading
head(scored_train_glm)
# -- testing 
predict(logistic_glm, bake_test, type = "prob") %>%
  bind_cols(.,predict(logistic_glm, bake_test)) %>%
  bind_cols(.,bake_test) -> scored_test_glm
## Warning in predict.lm(object, newdata, se.fit, scale = 1, type = if (type == :
## prediction from a rank-deficient fit may be misleading

## Warning in predict.lm(object, newdata, se.fit, scale = 1, type = if (type == :
## prediction from a rank-deficient fit may be misleading
head(scored_test_glm)

5.4 logistic regression reduced model

# -- training predictions from reduced model
predict(logistic_step1, bake_steptrain, type = "prob") %>%
  bind_cols(.,predict(logistic_step1, bake_steptrain)) %>%
  bind_cols(.,bake_steptrain) -> scored_train_step1

head(scored_train_step1)
# -- testing predictions from reduced model
predict(logistic_step1, bake_steptest, type = "prob") %>%
  bind_cols(.,predict(logistic_step1, bake_steptest)) %>%
  bind_cols(.,bake_steptest) -> scored_test_step1

head(scored_test_step1)

6. Evaluate

6.1 Decision tree 1

options(yardstick.event_first = FALSE)
# -- AUC: Train and Test 
scored_train_tree %>% 
  metrics(target_buy, .pred_1, estimate = .pred_class) %>%
  mutate(part="training") %>%
  bind_rows( scored_test_tree %>% 
               metrics(target_buy, .pred_1, estimate = .pred_class) %>%
               mutate(part="testing") 
  ) 
## Warning: The `yardstick.event_first` option has been deprecated as of yardstick 0.0.7 and will be completely ignored in a future version.
## Instead, set the following argument directly in the metric function:
## `options(yardstick.event_first = TRUE)`  -> `event_level = 'first'` (the default)
## `options(yardstick.event_first = FALSE)` -> `event_level = 'second'`
## This warning is displayed once per session.
# -- Variable Importance top 10 features  
org_tree %>%
  vip(num_features = 5)

# -- ROC Charts 
scored_train_tree %>%
  mutate(model = "train") %>%
  bind_rows(scored_test_tree %>%
              mutate(model="test")) %>%
  group_by(model) %>%
  roc_curve(target_buy, .pred_1) %>%
  autoplot()

# -- Confustion Matricies  
scored_train_tree %>%
  conf_mat(target_buy, .pred_class) %>%
  autoplot( type = "heatmap") +
  labs(title="Train Confusion Matrix")

scored_test_tree %>%
  conf_mat(target_buy, .pred_class) %>%
  autoplot( type = "heatmap") +
  labs(title="Test Confusion Matrix")

6.2 decision tree 2

options(yardstick.event_first = FALSE)
# -- AUC: Train and Test 
scored_train_tree2 %>% 
  metrics(target_buy, .pred_1, estimate = .pred_class) %>%
  mutate(part="training") %>%
  bind_rows(scored_test_tree2 %>% 
               metrics(target_buy, .pred_1, estimate = .pred_class) %>%
               mutate(part="testing") 
  ) 
# -- Variable Importance top 10 features  
org_tree %>%
  vip(num_features = 5)

# -- ROC Charts 
scored_train_tree2 %>%
  mutate(model = "train") %>%
  bind_rows(scored_test_tree2 %>%
              mutate(model="test")) %>%
  group_by(model) %>%
  roc_curve(target_buy, .pred_1) %>%
  autoplot()

# -- Confustion Matricies  
scored_train_tree2 %>%
  conf_mat(target_buy, .pred_class) %>%
  autoplot( type = "heatmap") +
  labs(title="Train Confusion Matrix")

scored_test_tree2 %>%
  conf_mat(target_buy, .pred_class) %>%
  autoplot( type = "heatmap") +
  labs(title="Test Confusion Matrix")

6.3 logistic regression full model

# -- AUC: Train and Test 
scored_train_glm %>% 
  metrics(target_buy, .pred_1, estimate = .pred_class) %>%
  mutate(part="training") %>%
  bind_rows( scored_test_glm %>% 
               metrics(target_buy, .pred_1, estimate = .pred_class) %>%
               mutate(part="testing") ) 
# -- Variable Importance top 10 features  
logistic_glm %>%
  vip(num_features = 10)

# -- ROC Charts 
scored_train_glm %>%
  mutate(model = "train") %>%
  bind_rows(scored_test_glm %>%
              mutate(model="test")) %>%
  group_by(model) %>%
  roc_curve(target_buy, .pred_1) %>%
  autoplot()

# -- Confustion Matricies  
scored_train_glm %>%
  conf_mat(target_buy, .pred_class) %>%
  autoplot( type = "heatmap") +
  labs(title="Train Confusion Matrix")

scored_test_glm %>%
  conf_mat(target_buy, .pred_class) %>%
  autoplot( type = "heatmap") +
  labs(title="Test Confusion Matrix")

6.4 reduced model

# -- Evaluate Reduced Model
# -- AUC: Train and Test 
scored_train_step1 %>% 
  metrics(target_buy, .pred_1, estimate = .pred_class) %>%
  mutate(part="training") %>%
  bind_rows( scored_test_step1 %>% 
               metrics(target_buy, .pred_1, estimate = .pred_class) %>%
               mutate(part="testing") 
  )
options(yardstick.event_first = FALSE)
# -- ROC Charts 
scored_train_step1 %>%
  mutate(model = "train") %>%
  bind_rows(scored_test_step1 %>%
              mutate(model="test")) %>%
  group_by(model) %>%
  roc_curve(target_buy, .pred_1) %>%
  autoplot()

# -- Confustion Matricies  
scored_train_step1 %>%
  conf_mat(target_buy, .pred_class) %>%
  autoplot( type = "heatmap") +
  labs(title="Train Confusion Matrix")

scored_test_step1 %>%
  conf_mat(target_buy, .pred_class) %>%
  autoplot( type = "heatmap") +
  labs(title="Test Confusion Matrix")

Fit in new chart

1. subset chart

subset(neworg,select=c(dem_affl,dem_age,dem_cluster_group,
                       dem_gender,dem_reg,dem_tv_reg,prom_class,prom_spend,prom_time))->neworg
colnames(neworg)<-make.unique(names(neworg))
neworg

2. Bake

bake_neworg  <- bake(org_recipe, new_data = neworg) %>%
  mutate(dem_cluster_group_U=0,dem_tv_reg_C.Scotland=0)
## Warning:  There were 5 columns that were factors when the recipe was prepped:
##  'dem_cluster_group', 'dem_gender', 'dem_reg', 'dem_tv_reg', 'prom_class'.
##  This may cause errors when processing new data.

3. predict

predict(org_tree2, bake_neworg, type = "prob") %>%
  bind_cols(.,predict(org_tree2, bake_neworg)) %>%
  bind_cols(.,bake_neworg) -> scored_neworg_tree

head(scored_neworg_tree)

4.output table

write.table(scored_neworg_tree,"new_organics_prediction.csv",row.names=FALSE,col.names=TRUE,sep=",")